<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学院" prop="college">
        <el-input
          v-model="queryParams.college"
          placeholder="请输入学院"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="查阅教师" prop="supName">
        <el-input
          v-model="queryParams.supName"
          placeholder="请输入查阅教师"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="毕业届数" prop="graduateNum">
        <el-input
          v-model="queryParams.graduateNum"
          placeholder="请输入毕业届数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['course:paperReview:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['course:paperReview:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['course:paperReview:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['course:paperReview:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-info"
          size="mini"
          @click="tipsModal = true"
        >注意事项</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="paperReviewList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" width="60" align="center">
        <template slot-scope="scope">
          {{scope.$index + 1}}
        </template>
      </el-table-column>
      <el-table-column label="学院" align="center" prop="college" />
      <el-table-column label="学生姓名" align="center" prop="sName" />
      <el-table-column label="指导教师" align="center" prop="tName" />
      <el-table-column label="毕业届数" align="center" prop="graduateNum">
        <template slot-scope="scope">
          {{scope.row.graduateNum + "届"}}
        </template>
      </el-table-column>
      <el-table-column label="专业班级" align="center" prop="sClass" />
      <el-table-column label="查阅教师" align="center" prop="supName" />
      <el-table-column label="毕业论文(设计)复查评价" align="center" prop="paperReviewEvalFlag">
        <template slot-scope="scope">
          <div v-if="scope.row.paperReviewEvalFlag === '0'">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-circle-plus-outline"
              @click="toPaperReviewEval(scope.row)"
            >去评价</el-button>
          </div>
          <div v-else-if="scope.row.paperReviewEvalFlag === '1'">
            <el-tag type="success">已评价</el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="200px" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="openPaperReviewTable(scope.$index)"
          >查看复查表</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['course:paperReview:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['course:paperReview:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改论文(毕设)复查对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
      <el-row :gutter="15">
        <el-form ref="form" :model="form" :rules="rules" label-width="100px">
          <el-col :span="12">
            <el-form-item label="学院" prop="college">
              <el-input v-model="form.college" placeholder="请输入学院" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="毕业届数" prop="graduateNum">
              <el-input v-model="form.graduateNum" placeholder="格式如：2018" clearable>
                <template slot="append">届</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="学生姓名" prop="sName">
              <el-input v-model="form.sName" placeholder="请输入学生姓名" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="学号" prop="sNo">
              <el-input v-model="form.sNo" :maxlength="20" oninput ="value=value.replace(/[^0-9.]/g,'')" placeholder="请输入学号" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="指导教师" prop="tName">
              <el-input v-model="form.tName" placeholder="请输入指导教师" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="专业班级" prop="sClass">
              <el-input v-model="form.sClass" placeholder="请输入专业班级" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="查阅人意见" prop="supIdea">
              <span slot="label">
                <el-tooltip content="查阅人对此毕业设计（论文）的综合意见">
                <i class="el-icon-info"></i>
                </el-tooltip>
                查阅人意见
              </span>
              <el-input v-model="form.supIdea" type="textarea" :autosize="{ minRows: 3 ,maxRows: 5 }" placeholder="请输入内容" clearable />
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 查看本科毕业论文（设计）复查情况记录表 -->
    <el-dialog :title="title" :visible.sync="openTable" width="900px" append-to-body>
      <!-- 添加滚动条 -->
      <el-scrollbar style="height: 700px;">
        <el-descriptions class="margin-top" :model="paperReviewTable" title="重庆三峡学院本科毕业论文（设计）复查情况记录表" :column="3" border>
          <template slot="extra">
            {{"填表日期：" + parseTime(paperReviewTable.createTime, '{y}-{m}-{d}')}}
          </template>

          <el-descriptions-item>
            <template slot="label">
              学院
            </template>
            {{paperReviewTable.college}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              学生姓名
            </template>
            {{paperReviewTable.sName}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              学生学号
            </template>
            {{paperReviewTable.sNo}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              指导教师
            </template>
            {{paperReviewTable.tName}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              查阅教师
            </template>
            {{paperReviewTable.supName}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              毕业届数
            </template>
            {{paperReviewTable.graduateNum + "届"}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              专业班级
            </template>
            {{paperReviewTable.sClass}}
          </el-descriptions-item>
        </el-descriptions>
        <el-descriptions class="margin-top" :model="paperReviewTable" :column="1" border>
          <el-descriptions-item>
            <template slot="label">
              查阅人对此毕业设计（论文）的综合意见
            </template>
            {{paperReviewTable.supIdea}}
          </el-descriptions-item>
        </el-descriptions>

        <el-table :data="paperReviewTable.paperReviewItems" border style="width: 100%">
          <el-table-column label="序号" width="60" align="center">
            <template slot-scope="scope">
              {{scope.$index + 1}}
            </template>
          </el-table-column>
          <el-table-column prop="content" label="评价指标" />
          <el-table-column prop="options" width="300px" label="评价结果选项" />
          <el-table-column prop="mySituation" label="评价结果" align="center" width="80" />
        </el-table>
      </el-scrollbar>
    </el-dialog>

    <!-- 注意事项提示模态框 -->
    <el-dialog
      title="注意事项"
      :visible.sync="tipsModal"
      width="30%"
      center>
      <h3>注：</h3>
      <span>1.论文抽查人员应保持档案袋中材料顺序不变，交回论文时教学秘书要验收；</span><br/>
      <span>2.此表(即评价表)由查阅人分论文填写，一份论文一份表；</span><br/>
      <span>3.论文抽查结束后对有问题的论文，教评处将通知相关教学单位加以改正。</span><br/>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="tipsModal = false">我知道了</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { listPaperReview, getPaperReview, delPaperReview, addPaperReview, updatePaperReview, getPaperReviewTable } from "@/api/course/paperReview";

export default {
  name: "PaperReview",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 论文(毕设)复查表格数据
      paperReviewList: [],
      // 查看毕业论文(毕设)复查表数据
      paperReviewTable: {},
      // 查看毕业论文(毕设)复查表Modal
      openTable: false,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        college: null,
        supName: null,
        graduateNum: null,
      },
      // 表单参数
      form: {},
      // 注意事项提示模态框
      tipsModal: false,
      // 表单校验
      rules: {
        college: [
          { required: true, message: "学院不能为空", trigger: "blur" }
        ],
        sName: [
          { required: true, message: "学生姓名不能为空", trigger: "blur" }
        ],
        tName: [
          { required: true, message: "指导教师不能为空", trigger: "blur" }
        ],
        graduateNum: [
          { required: true, message: "毕业届数不能为空", trigger: "blur" }
        ],
        sClass: [
          { required: true, message: "专业班级不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询论文(毕设)复查列表 */
    getList() {
      this.loading = true;
      listPaperReview(this.queryParams).then(response => {
        this.paperReviewList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        college: null,
        sName: null,
        tName: null,
        supName: null,
        graduateNum: null,
        sClass: null,
        sNo: null,
        supIdea: null,
        paperReviewEvalFlag: null,
        createBy: null,
        updateBy: null,
        createTime: null,
        updateTime: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加论文(毕设)复查";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPaperReview(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改论文(毕设)复查";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePaperReview(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPaperReview(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除论文(毕设)复查编号为"' + ids + '"的数据项？').then(function() {
        return delPaperReview(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('course/paperReview/export', {
        ...this.queryParams
      }, `paperReview_${new Date().getTime()}.xlsx`)
    },
    /** 去评价按钮操作 */
    toPaperReviewEval(row) {
      const paperReviewId = row.id
      this.$router.push({ path: '/course/paperReviewEval/toPREval', query: { paperReviewId: paperReviewId, pageNum: this.queryParams.pageNum } });
    },
    /** 查看复查表按钮操作 */
    openPaperReviewTable(index) {
      const no = index
      const list = this.paperReviewList[no]
      getPaperReviewTable(list).then((res) => {
        console.log(res);
        this.paperReviewTable = res
        this.openTable = true;
        this.title = "查看本科毕业论文（设计）复查表";
      })
    }
  }
};
</script>

<style scoped>
div /deep/ .el-scrollbar__wrap {
  overflow-x: hidden;
}
</style>